package com.playball.lottery.adapter;

import android.content.Context;
import android.media.Image;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.playball.lottery.R;
import com.playball.lottery.bean.Tab1Bean;
import com.playball.lottery.util.LotUtil;
import com.playball.lottery.util.province.GlobalUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/16.
 */

public class GridViewAdapter extends BaseAdapter {
    public  Context context;
    final String[] strArray;
    final String[] strang;
    private LayoutInflater inflater;

    public   GridViewAdapter(Context context,   String[] strArray ,String[] strang){
        this.context=context;
        this.strArray = strArray;
        this.strang=strang;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return strArray == null ? 0 : strArray.length;
    }

    @Override
    public Object getItem(int i) {
        return strArray[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        final GridViewAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new GridViewAdapter.ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.gridview_list, viewGroup,false);
            viewHolder.img_jia=(ImageView) convertView.findViewById(R.id.img_jia);
            viewHolder.img_logo=(ImageView) convertView.findViewById(R.id.img_logo);
            viewHolder.tv_typename=(TextView) convertView.findViewById(R.id.tv_typename);
            viewHolder.tv_msg=(TextView) convertView.findViewById(R.id.tv_msg);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (GridViewAdapter.ViewHolder) convertView.getTag();
        }
//
        String str=strArray[i].replace("[","").replace("]","");
//        int num=Integer.valueOf(str);
        str = str.substring(1, str.length()-1);
        int ilotId = Integer.valueOf(str);

        if (strang!=null&&strang.length>0){
            for (int j = 0; j < strang.length; j++) {
                int Starts=Integer.valueOf(strang[j].substring(0, 3));
                int Ends=Integer.valueOf(strang[j].substring(4));
                if (Starts == ilotId&&Ends!=0) {
                    viewHolder.img_jia.setVisibility(View.VISIBLE);
                    viewHolder.tv_msg.setText("加奖：" + Ends + "%");
                    viewHolder.tv_msg.setVisibility(View.VISIBLE);
                    break;
                } else {
                    viewHolder.img_jia.setVisibility(View.GONE);
                    viewHolder.tv_msg.setVisibility(View.INVISIBLE);
                }
            }
        }

        viewHolder.tv_typename.setText(LotUtil.getLotNamebyID(ilotId));
//        viewHolder.tv_msg.setText(str);

//        viewHolder.img_jia.setImageResource(LotUtil.getLotIconIDByName(LotUtil.getLotNamebyID(Integer.valueOf(strArray[i]))));
        viewHolder.img_logo.setImageResource(LotUtil.getLotIconIDByName(LotUtil.getLotNamebyID(ilotId)));

        return convertView;
    }


    public class ViewHolder {
        ImageView img_jia;//加奖图片
        ImageView img_logo;//logo
        TextView tv_typename;//彩种名称
        TextView tv_msg;//说明信息
    }
}
